package com.zzyl.serve.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.common.constant.HttpStatus;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.serve.domain.NursingProject;
import com.zzyl.serve.dto.PageQueryDTO;
import com.zzyl.serve.service.INursingProjectService;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@ApiModel("小程序端-服务项接口")
@RestController
@RequestMapping("member/orders/project")
public class MemberOrderProjectController {

    @Autowired
    private INursingProjectService iNursingProjectService;

    /**
     * 小程序分页查询护理项目列表
     *
     * @param pageQueryDTO
     * @return
     */
    @GetMapping("page")
    public TableDataInfo page(PageQueryDTO pageQueryDTO) {
        Page<NursingProject> nursingProjectPage = iNursingProjectService.pageQuery(pageQueryDTO);
        return getDataTable(nursingProjectPage);
    }

    /**
     * 根据编号查询护理项目信息
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R<NursingProject> getById(@PathVariable Integer id) {
        NursingProject project = iNursingProjectService.getById(id);
        return R.ok(project);
    }

    /**
     * 响应小程序请求分页数据
     *
     * @param page
     * @return
     */
    protected TableDataInfo getDataTable(Page<?> page) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(page.getRecords());
        rspData.setTotal(page.getTotal());
        return rspData;
    }
}
